package com.example.heiton.tablayoutwithviewpage.Model.Http;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.heiton.tablayoutwithviewpage.Bean.Photos500px;
import com.example.heiton.tablayoutwithviewpage.UI.Adapter.MyStaggerAdapter;
import com.example.heiton.tablayoutwithviewpage.UI.Adapter.MyrecycleViewAdapter;
import com.example.heiton.tablayoutwithviewpage.UI.injaction.ITab1;
import com.example.heiton.tablayoutwithviewpage.UI.injaction.ITab2;

/**
 * Created by 17930 on 2016/2/8.
 */
public class VolleyDo {
    private String Url;

    private ITab1 tab1;
    private ITab2 tab2;

    public VolleyDo(Context context, ITab2 tab2) {
        this.context = context;
        this.tab2 = tab2;
    }

    public VolleyDo( ITab1 tab1, Context context) {

        this.tab1 = tab1;
        this.context = context;
    }

    private Context context;

    public String VolleyDoGet(String url){
        String req=null;
        RequestQueue requserQueue= Volley.newRequestQueue(context);
        StringRequest sr=new StringRequest(Request.Method.GET,url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                Photos500px photo=new Photos500px(response);

                if (photo.getPhotosList()!=null){



                    if(tab1!=null)
                    {

                        tab1.SetRecycleViewManage(new GridLayoutManager(context,2));

                        MyrecycleViewAdapter myadapter=new MyrecycleViewAdapter(photo,context);
                tab1.SetRecycleViewAdapter(myadapter);
                    tab1.SetSwipeCancanRefresh(true);
                    tab1.SetSwipeType(false);

                }
                  if (tab2!=null){
                        MyStaggerAdapter myStaggerAdapter=new MyStaggerAdapter(context,photo);
                        tab2.SetStaggerAdapter(myStaggerAdapter);
                        tab2.SetSwipeType(false);
                    }

                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("volleyError",error.getMessage());
                Log.e("push","");
            }
        });
        requserQueue.add(sr);
        return  req;
    }
}
